﻿@using System.Collections.Generic
@using System.Web.Optimization

@using JavaScriptEngineSwitcher.Core
@using JavaScriptEngineSwitcher.Msie

@using BundleTransformer.Core.Bundles
@using BundleTransformer.Core.Orderers

@using WebMarkupMin.AspNet.Brotli
@using WebMarkupMin.AspNet.Common
@using WebMarkupMin.AspNet.Common.Compressors
@using WebMarkupMin.AspNet.Common.UrlMatchers
@using WebMarkupMin.AspNet4.Common
@using WebMarkupMin.Core
@using WebMarkupMin.Core.Loggers
@using WebMarkupMin.MsAjax

@{
	#region JavaScript Engine Switcher

	JsEngineSwitcher.Current.EngineFactories
		.AddMsie()
		;

	#endregion

	#region Bundle Transformer

	var bundles = BundleTable.Bundles;
	bundles.UseCdn = true;

	var nullOrderer = new NullOrderer();

	var commonStylesBundle = new CustomStyleBundle("~/Bundles/CommonStyles");
	commonStylesBundle.Include("~/Content/app.less");
	commonStylesBundle.Orderer = nullOrderer;

	bundles.Add(commonStylesBundle);

	var modernizrBundle = new CustomScriptBundle("~/Bundles/Modernizr");
	modernizrBundle.Include("~/Scripts/modernizr-2.*");
	modernizrBundle.Orderer = nullOrderer;

	bundles.Add(modernizrBundle);

	var jQueryBundle = new CustomScriptBundle("~/Bundles/Jquery",
		"http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.10.2.min.js");
	jQueryBundle.Include("~/Scripts/jquery-{version}.js");
	jQueryBundle.Orderer = nullOrderer;
	jQueryBundle.CdnFallbackExpression = "window.jquery";

	bundles.Add(jQueryBundle);

	var commonScriptsBundle = new CustomScriptBundle("~/Bundles/CommonScripts");
	commonScriptsBundle.Include("~/Scripts/bootstrap.js");
	commonScriptsBundle.Orderer = nullOrderer;

	bundles.Add(commonScriptsBundle);

	#endregion

	#region WebMarkupMin

	WebMarkupMinConfiguration configuration = WebMarkupMinConfiguration.Instance;
	configuration.AllowMinificationInDebugMode = true;
	configuration.AllowCompressionInDebugMode = true;

	DefaultLogger.Current = new ThrowExceptionLogger();
	DefaultCssMinifierFactory.Current = new MsAjaxCssMinifierFactory();
	DefaultJsMinifierFactory.Current = new MsAjaxJsMinifierFactory();

	IHtmlMinificationManager htmlMinificationManager = HtmlMinificationManager.Current;
	htmlMinificationManager.ExcludedPages = new List<IUrlMatcher>
	{
		new ExactUrlMatcher("/Contact")
	};
	HtmlMinificationSettings htmlMinificationSettings = htmlMinificationManager.MinificationSettings;
	htmlMinificationSettings.RemoveRedundantAttributes = true;
	htmlMinificationSettings.RemoveHttpProtocolFromAttributes = true;
	htmlMinificationSettings.RemoveHttpsProtocolFromAttributes = true;

	IXhtmlMinificationManager xhtmlMinificationManager = XhtmlMinificationManager.Current;
	xhtmlMinificationManager.IncludedPages = new List<IUrlMatcher>
	{
		new ExactUrlMatcher("/Contact")
	};
	XhtmlMinificationSettings xhtmlMinificationSettings = xhtmlMinificationManager.MinificationSettings;
	xhtmlMinificationSettings.RemoveRedundantAttributes = true;
	xhtmlMinificationSettings.RemoveHttpProtocolFromAttributes = true;
	xhtmlMinificationSettings.RemoveHttpsProtocolFromAttributes = true;

	IXmlMinificationManager xmlMinificationManager = XmlMinificationManager.Current;
	XmlMinificationSettings xmlMinificationSettings = xmlMinificationManager.MinificationSettings;
	xmlMinificationSettings.CollapseTagsWithoutContent = true;

	IHttpCompressionManager httpCompressionManager = HttpCompressionManager.Current;
	httpCompressionManager.CompressorFactories = new List<ICompressorFactory>
	{
		new BrotliCompressorFactory(new BrotliCompressionSettings
		{
			Level = 1
		}),
		new DeflateCompressorFactory(),
		new GZipCompressorFactory()
	};

	#endregion
}